Thread: Help me about postgreSql code

Help me about postgreSql code

From
Elian Laura
Date:
Hello,
I´m an undergraduate in Peru in systems engineering.
I need to know about how does postgres work with the definition of data type in run time.
I downloaded de source code of postgres, but es very complex, at least I would like to know in which part of the code is the recognition of a data that the user enters. I write a data in a field and the postgress must know what kind it is, as it do that?

I hope your help.

Thanks

Atte.
Elian


Re: Help me about postgreSql code

From
John R Pierce
Date:
Elian Laura wrote:
> Hello,
> I´m an undergraduate in Peru in systems engineering.
> I need to know about how does postgres work with the definition of
> data type in run time.
> I downloaded de source code of postgres, but es very complex, at least
> I would like to know in which part of the code is the recognition of a
> data that the user enters. I write a data in a field and the postgress
> must know what kind it is, as it do that?

postgres is, at the core,  a relational database engine with a SQL
language processor, it doesn't know what a 'field' is.

the fundamental storage units of a relational database are tables made
of rows made of columns.  a column of a row of a given table is akin to
a field, but on disk these are stored in a binary representation, the
typing information required to decode it is part of the table definition.

the only user 'input' is SQL statements, such as...

    CREATE TABLE users (uid INTEGER, username TEXT, firstname TEXT,
lastname TEXT);

    INSERT INTO users (uid, username) VALUES (103, 'jpierce', 'John',
'Pierce'), ('104', 'elaura', 'Elian', 'Laura');

    SELECT username,firstname,lastname FROM users WHERE uid=103;

(I use all upper case letters for SQL keywords to distinguish them, in
fact, SQL doesn't care)

Things like forms, fields, human input decoding  are the domain of the
user application software, which will generate and execute SQL
statements to store the data in the database.


Is this clear enough?




Re: Help me about postgreSql code

From
John R Pierce
Date:
Elian Laura wrote:
> i understand, but why my teacher wrote in his paper.."Probably the
> most obvious case is a database engine where the user defines, at run
> time, if a field is integer, char, float, etc. but, it is not
> necessary to compile the program again. All this felxibility must be
> ........."

I have no idea why your teacher wrote that.   You should ask them.

in a relational database, all data fields are typed.   the only "user
input" that Postgres processes is the SQL language, and thats a full
blown complex language parser, the internals of which I have little
desire to take apart.



Re: Help me about postgreSql code

From
Mark Morgan Lloyd
Date:
John R Pierce wrote:
> Elian Laura wrote:
>> i understand, but why my teacher wrote in his paper.."Probably the
>> most obvious case is a database engine where the user defines, at run
>> time, if a field is integer, char, float, etc. but, it is not
>> necessary to compile the program again. All this felxibility must be
>> ........."

I am not a PostgreSQL developer but I think the thing to understand here
is that there are two stages involved. If I say much more I think I'll
be guilty of doing your homework for you, I suggest that you look very
carefully at the examples John gave you earlier and consider that from
the viewpoint of the database engine they are being entered at runtime.

 >>>   CREATE TABLE users (uid INTEGER, username TEXT, firstname TEXT,
 >>> lastname TEXT);
 >>>
 >>>   INSERT INTO users (uid, username) VALUES (103, 'jpierce', 'John',
 >>> 'Pierce'), ('104', 'elaura', 'Elian', 'Laura');
 >>>
 >>>   SELECT username,firstname,lastname FROM users WHERE uid=103;

If you think about it one of those statements is giving the system
information which it can store (I'm not sure the way it does this is
really important) and re-use.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]