Comments (6)
This indeed isn't supported. The main obstacle is to get at the name of the primary key sequence.
from go-pgsql.
Subscribing, very useful
from go-pgsql.
If you use not ancient PostgreSQL, you can do insert into <table> ... returning <id-column>
and read it like normal select
statement, e.g. Scan()
.
from go-pgsql.
Yes, returning is nice, but to implement LastInsertId, how would we know the exact name of the id column without guessing?
from go-pgsql.
I guess there is no way without fetching table structure. And even then you can't do anything for table like id1 serial, id2 serial, primary key (id1, id2)
.
Basically, LastInsertId
interface is not as generic as SQL standard. That's why i'm suggesting him to use other way to get inserted ids.
from go-pgsql.
I'm using "SELECT LASTVAL()" which appears to work OK, and alternatively a query using eg. " RETURNING iKey" appears to work OK.
from go-pgsql.
Related Issues (12)
- generated Keys HOT 2
- Example for insert query with placeholders? HOT 1
- the database/sql interface can not handle the time.Time HOT 7
- go-pgsql can not handle CHAR type field HOT 1
- COPY table from stdin HOT 5
- Link to examples not working (404)
- decimal implemented as big.Rat instead of float64 HOT 2
- go1.3 compatibility issue HOT 2
- numerical result is out of range -- error HOT 1
- Pools... HOT 8
- Directory layout HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-pgsql.